/* 
 * File:   System.cpp
 * Author: Gerralt
 * 
 * Created on 14 februari 2012, 15:12
 */

#include "System.h"
#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

System::System() {
}

System::System(const System& orig) {
}

System::~System() {
}

void System::printDataTypeSizes() {
    string halloString = "Hallo";
    string halloStringNewRule = "Hallo\n";
    string* pointerHalloString = &halloString;
    char eenChar = 'h';

    int integertje = 123;
    long longtje = 1234566677;
    double doubletje = 1234.23;
    float floatje = 21345;
    short shortje = 123;

    bool booleantje = false;

    cout << "Datatype          | Size\n";
    cout << "-------------------------------\n";
    cout << "\"Hallo\"           | " << halloString.size() << "\n";
    cout << "\"Hallo\\n\"         | " << halloStringNewRule.size() << "\n";
    cout << "*Hallo->          | " << pointerHalloString->size() << "\n";
    cout << "*Hallo size       | " << sizeof (pointerHalloString) << "\n";
    cout << "char h            | " << sizeof (eenChar) << "\n";
    cout << "this class size   | " << sizeof (System) << "   // is dus een pointer! \n";
    cout << "integer size      | " << sizeof (integertje) << "\n";
    cout << "long size         | " << sizeof (longtje) << "\n";
    cout << "double size       | " << sizeof (doubletje) << "\n";
    cout << "float size        | " << sizeof (floatje) << "\n";
    cout << "short size        | " << sizeof (shortje) << "\n";
    cout << "boolean size      | " << sizeof (booleantje) << "\n";
}

bool System::compare(const string & file1, const string & file2) {
    string line1;
    string line2;
    ifstream myfile1(file1.c_str());
    ifstream myfile2(file2.c_str());

    bool correct = true;
    if (myfile1.is_open() && myfile2.is_open()) {
        while (myfile1.good()) {
            getline(myfile1, line1);
            if (myfile2.good()) {
                getline(myfile2, line2);
                if (line1 != line2) {
                    correct = false;
                }
            } else {
                correct = false;
            }
        }
        if (myfile2.good()) {
            correct = false;
        }
        myfile1.close();
        myfile2.close();
        return correct;
    }
}

bool System::compare(const string & command, const string & file1, const string & file2) {
    if (command != "-d") {
        return compare(file1, file2);
    } else {
        string line1;
        string line2;
        ifstream myfile1(file1.c_str());
        ifstream myfile2(file2.c_str());

        int lineNumber = 1;

        bool correct = true;
        if (myfile1.is_open() && myfile2.is_open()) {
            while (myfile1.good()) {
                getline(myfile1, line1);
                if (myfile2.good()) {
                    getline(myfile2, line2);
                    if (line1 != line2) {
                        cout << "Line numer " << lineNumber << " isn't the same!";
                        correct = false;
                    }
                } else {
                    cout << "File 1, line number " << lineNumber << " doesn't exist in file 2!";
                    correct = false;
                }
                lineNumber++;
            }
            while (myfile2.good()) {
                cout << "File 1, line number " << lineNumber << " doesn't exist in file 2!";
                correct = false;
                lineNumber++;
            }
            myfile1.close();
            myfile2.close();
            return correct;
        }
    }
}